/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kylingroup.J2SE.Thread;

/**
 *
 * @author kylin
 */
public class TestThreadSynchronized2 implements Runnable{
    int b=100;
    public synchronized void method1() throws Exception{
        b=1000;
        Thread.sleep(5000);
        System.out.println("b="+b);
    }
    public void method2(){
        System.out.println(b);
    }
    public void run(){
        try{
            method1();
        }catch(Exception e){
            e.printStackTrace();
        }
    }
    public static void main(String args[]) throws Exception{
        TestThreadSynchronized2 t=new TestThreadSynchronized2();
        Thread th=new Thread(t);
        th.start();
        Thread.sleep(1000);//主线程睡眠1秒，以保证th线程已经运行
        t.method2();//method2没有被锁定，所以method2可以在method1执行过程中被执行。所以打印b=1000,否则将打印100。（个人理解-也就是说可以通过对象中未经锁定的资源去访问锁定资源。）
    }
}
